﻿using Autofac;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace SW.EF.Core
{
    public class AutofacProvider : IIocProvider
    {
        private static ContainerBuilder _builder = new ContainerBuilder();
        private IContainer _container;

        public IContainer Register()
        {
            _builder.RegisterAssemblyTypes(Assembly.Load("SW.EF.BLL")).Where(p => p.Name.EndsWith("Service")).AsImplementedInterfaces();
            _builder.RegisterAssemblyTypes(Assembly.Load("SW.EF.BLL")).Where(x => x.Name.EndsWith("Manager")).AsImplementedInterfaces();
            _container = _builder.Build();
            return _container;
        }

        public T Resolve<T>()
        {
            return _container.Resolve<T>();
        }
    }
}
